package week_six;

public class HouseRobber_198 {
    public int rob(int[] nums) {
        int n = nums.length;
        int[] houses = new int[n + 1];
        for (int i = 1; i <= n; i++) houses[i] = nums[i - 1];

        int[][] f = new int[n + 1][2];
        // for(int i=0;i<=n;i++) {
        //     Arrays.fill(f[i], -1000000);
        // }
        f[0][0] = 0;
        f[0][1] = -100000;


        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= 1; j++) {
                f[i][0] = Math.max(f[i - 1][1], f[i - 1][0]);
                f[i][1] = f[i - 1][0] + houses[i];
            }
        }

        return Math.max(f[n][0], f[n][1]);
    }

}
